
version 15
capture log close
set more off
clear
clear matrix
clear mata

if c(username)=="WB485280" {
		glo rootdir		"C:\Users\wb485280\OneDrive - WBG\radicalization"
		}
if c(username)=="WB382635" {
		glo rootdir		"C:\Users\wb382635\Dropbox\Unemp & daesh"
		}
if c(username)=="WB452275" {
		glo rootdir		"C:\Users\WB452275\Dropbox\Projects\Unemp & daesh"
		}
if c(username)=="sarurchaudhary" {
		glo rootdir		"/Users/sarurchaudhary/Dropbox/Unemp & daesh"
		}
if c(username)=="kartikabhatia" {
			glo rootdir		"/Users/kartikabhatia/Dropbox/Before2019/Unemp & daesh"
			}
			
		glo	datadir     "${rootdir}/Data/Raw data"
		glo outdir		"${rootdir}/Data/Working datasets"
		glo dodir		"${rootdir}/Dofiles"
        
		cd "${outdir}"
		


* ------------------------------------------------------------------------------

* Date : March 2021 [Checked Oct 2021]

* Project : Daesh FF Working Paper (The World Bank)

* This is the do file for calculating flight ticket prices

* ------------------------------------------------------------------------------
			
// TICKET DATA COMPILATION

			foreach year in 2019 2013 {
			foreach country in Turkey Iraq {
				
				*cd "C:\Users\wb382635\Dropbox\Unemp & daesh\Data\Working datasets\Ticket_data"
				insheet using "${outdir}/Ticket_data/all_to_tky_irq_`year'_JobId1746122.CSV", clear
				ren avgfaretotal price
				drop if price==0
				keep if arrcountryname==`"`country'"' 

			collapse (mean) mnp_`country'=pr (median) mdp_`country'=pr (min) minp_`country'=pr (max) maxp_`country'=pr (mean) km_`country'=gcdkm , by(depcountrycode depcountryname)


					ren depcountryname countryname
					ren depcountrycode countrycode_tickets

					replace countryname="Gambia, The" if countryname=="Gambia"
					replace countryname="Congo Kinshasa" if countryname=="Congo Democratic Republic of"
					replace countryname="Congo Brazzaville" if countryname=="Congo"
					replace countryname="Egypt, Arab Rep." if countryname=="Egypt"
					replace countryname="Hong Kong SAR, China" if countryname=="Hong Kong (sar) China"
					replace countryname="Iran, Islamic Rep." if countryname=="Iran Islamic Republic of"
					replace countryname="Ireland" if countryname=="Ireland Republic of"
					replace countryname="Ivory Coast" if countryname=="Cote D'Ivoire"
					replace countryname="Kyrgyz Republic" if countryname=="Kyrgyzstan"
					replace countryname="Lao PDR" if countryname=="Lao People's Democratic Republic"
					replace countryname="Macedonia, FYR" if countryname=="Macedonia Former Yugoslav Republic of"
					replace countryname="Moldova" if countryname=="Moldova Republic of"
					replace countryname="Slovak Republic" if countryname=="Slovakia"
					replace countryname="South Korea" if countryname=="Korea Republic of"
					replace countryname="Taiwan" if countryname=="Chinese Taipei"
					replace countryname="Tanzania" if countryname=="Tanzania United Republic of"
					replace countryname="United States" if countryname=="USA"
					replace countryname="Venezuela, RB" if countryname=="Venezuela"
					replace countryname="Vietnam" if countryname=="Viet Nam"
					replace countryname="Yemen, Rep." if countryname=="Yemen"


				*For Kosovo, use ticket cost for Montenegro 
					preserve
					keep if countryname=="Montenegro"
					replace countryname="Kosovo" if  countryname=="Montenegro"
					tempfile kosovo
					sa `kosovo'
					restore
					append using `kosovo'
				
					
				tempfile temp`country'_`year'
				sa `temp`country'_`year''
				}
				}
				
				u `tempTurkey_2019'
				merge 1:1 countryname using `tempIraq_2019'
				drop _merge
				keep if countryname=="Trinidad and Tobago"
				tempfile trinidad
				sa `trinidad'
				
				u `tempTurkey_2013'
				merge 1:1 countryname using `tempIraq_2013'
				drop _merge
				append using `trinidad'
				
			sa "${outdir}/tickets.dta", replace  
